<?php
	require_once("user.inc");
	require_once("lib.inc");
	$retVal = array(
		'success' => false,
		'message' => '',
	);		
	$method = getParam('__m');
	$params= getParam('__d');
	if(!is_null($params)){
		$paramArray = json_decode(urldecode(getParam('__d')),true);
	}
	if(!is_null($params) && is_array($params)) {
		foreach($paramArray as &$value){
			$value = $rwConn->real_escape_string($value);
		}	
	}
	$anonymousOK = array('getUidFromEmail','login','register','isLoggedIn');
	$userObj = new User($rwConn);

	if(!in_array($method,get_class_methods($userObj))){
		$retVal['message'] = 'Invalid API call.';
		returnAPI($retVal);
	}
	$isLoggedInResult = $userObj->isLoggedIn();
	if(!$isLoggedInResult['success'] && !in_array($method,$anonymousOK)){
		$retVal['message'] = 'You must be logged in.';
                returnAPI($retVal);
	}

	$methodReturn = $userObj->$method();
	if(isset($methodReturn['success'])){
		$retVal['success'] = $methodReturn['success'];
		unset($methodReturn['success']);
	}
	if(isset($methodReturn['message'])){
		$retVal['message'] = $methodReturn['message'];
		unset($methodReturn['message']);
	}

	$retVal = array_merge($retVal,$methodReturn);
	returnAPI($retVal);

?>
